import telnetlib

def tn_ready(device_15,mgmt_ip,username,password):
    tn = telnetlib.Telnet(mgmt_ip)
    tn.read_until(b'Username:')
    tn.write(username.encode('ascii') + b'\n')
    tn.read_until(b'Password:')
    tn.write(password.encode('ascii') + b'\n')
    tn.read_until(device_15.encode('ascii'))
    tn.write('terminal length 0'.encode('ascii') + b'\n')
    tn.read_until(device_15.encode('ascii'))
    return tn

